#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <bitset>
#include <utility>
using namespace std;

#define mm(a, n) memset(a, n, sizeof a)
#define mk(a, b) make_pair(a, b)
#define FOR(i, a, b) for (int i = a; i <= b; i++)
#define DOW(i, a, b) for (int i = b; i >= a; --i)

const double eps = 1e-6;
const int INF = 0x3f3f3f3f;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef pair<LL, LL> PLL;
typedef pair<int, LL> PIL;

inline void quickread()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

const int N = 110;

int g[N][N], f[N][N];
int n, m;

int Max(int i, int j)
{
    int res = max(f[i - 3][j], max(f[i - 2][j], f[i - 1][j]));
    res = max(res, max(f[i][j - 1], max(f[i - 1][j - 1], f[i - 2][j - 1])));
    res = max(res, max(f[i][j - 1], max(f[i][j - 2], f[i - 1][j - 2])));
    return res;
}

inline void solution()
{
    memset(f, -INF, sizeof f);
    cin >> n >> m;
    for (int i = 5; i <= n + 4; i++)
        for (int j = 5; j <= m + 4; j++)
            cin >> g[i][j];

    f[5][5] = g[5][5];
    for (int i = 5; i <= n + 4; i++)
        for (int j = 5; j <= m + 4; j++)
        {
            if (i == 5 && j == 5)
                continue;
            f[i][j] = Max(i, j) + g[i][j];
        }
    cout << f[n + 4][m + 4] << endl;
}

int main()
{
    freopen("input.txt", "r", stdin);
    quickread();
    solution();
    return 0;
}